person = {
    'name': '小米',
    'age': 12,
    'gender': '男',
    'height': 1.75
}
print(person, type(person))

# 空置
d1 = {}
print(d1, type(d1))
d2 = {'name': '小米', 'age': 12}
print(d2, type(d2))

print("*" * 20)

# 类型转换
d3 = dict(a=1, b=2)
print(d3, type(d3))
d4 = dict([('a', 1), ('b', 2)])
print(d4, type(d4))

print("*" * 20)
# 新增键值对
person['phone'] = '15955456212'
print(person)

# 获取键值
print(person['name'])

# 修改键值对
person['name'] = "大米"
print(person)
print("*" * 20)

# in 判断键值对是否存在
print("name" in person)

print("*" * 20)

# 遍历
for i in person:
    print(i)

print("*" * 20)

print(person.items())  # 里面是列表
for k, v in person.items():
    print(k, v)

print("*" * 20)

for k in person.keys():
    print(k)

print("*" * 20)

for v in person.values():
    print(v)
print("=" * 20)

# 字典的常用方法
# 删除
person.pop("name")  # 删除
print("pop:",person)

# 复制
a = person.copy()
print("copy::",a)

# 获取键值
print("get:", person.get("gender"))

# 删除末尾键值对
person.popitem()
print("popitem:", person)

# 更新键值
person.update({'age':22,'school':'北大'})
print("update:",person)

# 清空
person.clear()
print("clear:",person)
